package com.pactera.madp.cp.controller.oms.workroom;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pactera.madp.common.core.util.R;
import com.pactera.madp.common.log.annotation.SysLog;
import com.pactera.madp.cp.api.em.permission.ReqPerEnum;
import com.pactera.madp.cp.api.dto.ReqRoomAutoPullCreateDTO;
import com.pactera.madp.cp.api.dto.ReqRoomAutoPullUpdateDTO;
import com.pactera.madp.cp.service.IWorkRoomAutoPullService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author: yangpengwei
 * @time: 2020/12/16 4:16 下午
 * @description 自动拉群管理
 */
@RestController
@AllArgsConstructor
@RequestMapping("/workroomautopull")
@Api(value = "workroomautopull", tags = "自动拉群管理")
public class WorkRoomAutoPullController {

    private IWorkRoomAutoPullService workRoomAutoPullService;

    @GetMapping("/page")
    @ApiOperation(value = "自动拉群管理列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="qrcodeName",value="群二维码名称",dataType ="String"),
            @ApiImplicitParam(name="permission",value="权限:ALL-全部,DEPARTMENT-部门,EMPLOYEE-员工")
    })
    public R getList(@RequestParam(defaultValue = "") String qrcodeName,Page page,ReqPerEnum permission) {
        return workRoomAutoPullService.getList(qrcodeName, page, permission);
    }

    @SysLog("新建自动拉群")
    @PostMapping
    @ApiOperation(value = "新建自动拉群")
    public R createRoomAutoPull(@RequestBody ReqRoomAutoPullCreateDTO req) {
        workRoomAutoPullService.createRoomAutoPull(req);
        return R.ok();
    }

    @SysLog("修改自动拉群")
    @PutMapping
    @ApiOperation(value = "修改自动拉群")
    public R updateRoomAutoPullDetail(@RequestBody ReqRoomAutoPullUpdateDTO req) {
        workRoomAutoPullService.updateRoomAutoPullDetail(req);
        return R.ok();
    }

    @SysLog("删除自动拉群")
    @DeleteMapping
    @ApiOperation(value = "删除自动拉群")
    public R deleteRoomAutoPull(@RequestParam Integer id){
       return workRoomAutoPullService.removeById(id) ? R.ok("删除成功"):R.failed("删除失败");
    }

    @GetMapping("/{workRoomAutoPullId}")
    @ApiOperation(value = "自动拉群详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name="workRoomAutoPullId",value="自动拉群id",dataType ="String")
    })
    public R getRoomAutoPullDetail(@PathVariable Integer workRoomAutoPullId) {
        if(workRoomAutoPullId == null){
            return R.failed("workRoomAutoPullId 不能为空");
        }
        return R.ok(workRoomAutoPullService.getRoomAutoPullDetail(workRoomAutoPullId));
    }

}
